package com.qding.park.common.core.exceptions.handle;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.qding.park.common.core.exceptions.IExceptionHandle;
import com.qding.park.common.core.exceptions.business.adapter.AdapterException;
import com.qding.park.common.core.exceptions.business.manager.adapterfactory.AdapterProxyCreateFail;
import com.qding.park.common.core.exceptions.business.manager.service.ServiceCoreException;
import com.qding.park.common.core.exceptions.business.validator.RchlValidatorException;
import com.qding.park.common.core.exceptions.system.NetWorkException;
import com.qding.park.common.core.exceptions.system.SystemUnKnown;

@Component("commonExceptionHandle")
public class CommonExceptionHandle implements IExceptionHandle{
	private static final Log _log = LogFactory.getLog(CommonExceptionHandle.class);
	@Override
	public void handle(Exception e) {

		if (e instanceof AdapterException) {
			((AdapterException) e).handle();
		} else if (e instanceof AdapterProxyCreateFail) {
			((AdapterProxyCreateFail) e).handle();
		} else if (e instanceof ServiceCoreException) {
			((ServiceCoreException) e).handle();
		} else if (e instanceof RchlValidatorException) {
			((RchlValidatorException) e).handle();
		} else if (e instanceof NetWorkException) {
			((NetWorkException) e).handle();
		} else if (e instanceof SystemUnKnown) {
			((SystemUnKnown) e).handle();
		} else {
			_log.error(e.getMessage(), e);
		}

	}
	@Override
	public void handle(Throwable e) {
		if (e instanceof AdapterException) {
			((AdapterException) e).handle();
		} else if (e instanceof AdapterProxyCreateFail) {
			((AdapterProxyCreateFail) e).handle();
		} else if (e instanceof ServiceCoreException) {
			((ServiceCoreException) e).handle();
		} else if (e instanceof RchlValidatorException) {
			((RchlValidatorException) e).handle();
		} else if (e instanceof NetWorkException) {
			((NetWorkException) e).handle();
		} else if (e instanceof SystemUnKnown) {
			((SystemUnKnown) e).handle();
		} else {
			_log.error(e.getMessage(), e);
		}
		
	}

}
